<%--
  Created by IntelliJ IDEA.
  User: lt
  Date: 2017/8/17
  Time: 22:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>

<html>
<head>
    <title>部署工作流程</title>
    <%--<jsp:include page="../head.jsp"/>--%>

    <style type="text/css">
        .row{
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div class="row" id="app">
        <%--logger.error(String.format("流程定义Id：%s",pd.getId()));--%>
        <%--logger.error(String.format("流程定义名称：%s",pd.getName()));--%>
        <%--logger.error(String.format("流程定义key：%s",pd.getKey()));--%>
        <%--logger.error(String.format("流程定义版本：%s",pd.getVersion()));--%>
        <%--logger.error(String.format("流程定义bpmn文件：%s",pd.getResourceName()));--%>
        <%--logger.error(String.format("流程定义png文件：%s",pd.getDiagramResourceName()));--%>
        <%--logger.error(String.format("部署对象Id：%s",pd.getDeploymentId()));--%>
        <div style="width: 100%; background-color: navy; color: #ffffff;">部署的流程定义</div>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>流程定义Id</th>
                    <th>流程定义名称</th>
                    <th>流程定义key</th>
                    <th>流程定义版本</th>
                    <th>流程定义bpmn文件</th>
                    <th>流程定义png文件</th>
                    <th>部署对象Id</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(obj, index) in objects">
                    <td id="id">{{obj.id}}</td>
                    <td>{{obj.name}}</td>
                    <td id="key">{{obj.key}}</td>
                    <td id="version">{{obj.version}}</td>
                    <td>{{obj.resourceName}}</td>
                    <td>{{obj.diagramResourceName}}</td>
                    <td>{{obj.deploymentId}}</td>
                    <td :id="obj.key">{{obj.starts}}</td>
                    <td><a onclick="app.start()">启动流程</a></td>
                </tr>
            </tbody>
        </table>
        <div style="width: 100%; background-color: navy; color: #fffeff;">部署流程</div>
        <form action="" method="post" id="formDate">
            <div class="form-group">
                <label for="name">流程名称</label>
                <input type="text" class="form-control" id="name" name="name" placeholder="请输入名称">
            </div>
            <div class="form-group">
                <label for="fileToUpload">流程文件</label>
                <input type="file" name="fileToUpload" id="fileToUpload" />
                <p class="help-block">文件后缀.zip</p>
            </div>
            <button type="button" id="repository" class="btn btn-default" >提交</button>
        </form>
    </div>

    <script src="${contextPath}/static/statistics/js/vue.js"></script>
    <script type="text/javascript" >

        var layer = layui.layer;

        var app = new Vue({
            el: '#app',
            data: {
                objects: [],
            },
            methods: {
                findlastVerion: function () {
                    var param = {};
                    console.log(param);
                    $.ajax({
                        url: '${contextPath}/process/findlastVerion' ,
                        type: 'POST',
                        data: param,
                        async: false,
                        cache: false,
                        dataType: 'json',   //返回值类型
                        contentType: false,
                        processData: false,
                        success : function(data) {
                            console.log(data);
                            var arrayData = data.data;
                            app.objects = arrayData;
                        },
                        error : function(result) {
                            console.info("表单提交错误："+ result);
                        }
                    });
                },
                start: function () {
                    var key = $("#key").html();
                    $.ajax({
                        type: "POST",
                        url: '${contextPath}/process/start',
                        data: {key: key, tm:new Date().getTime()},
                        dataType:'json',
                        cache: false,
                        success: function(data){
                            console.log(data)
                            if(data.result){
                                layer.msg(data.message);

                            }else {
                                layer.msg(data.message);
                            }
                            // window.location.href = "findlastVerion";
                        }
                    });
                },
                repository: function () {
                    var formData = new FormData();
                    formData.append("inputfile", document.getElementById('fileToUpload').files[0]);
                    formData.append("name", document.getElementById('name').valueOf());
                    $.ajax({
                        type: "POST",
                        url: 'repository',
                        data: formData,
                        dataType:'json',
                        cache: false,
                        processData: false,
                        contentType: false,
                        success: function(data){
                            if(data.success){
                                layer.msg("部署成功！");
                                app.findlastVerion();
                            }else {
                                layer.msg("部署失败！");
                            }
                        },
                        error : function(result){
                            console.info("表单提交错误："+ result);
                        }

                    });
                }
            }
        });



        <%--$("#start").click(function () {--%>
            <%--var key = $("#key").html();--%>
            <%--$.ajax({--%>
                <%--type: "POST",--%>
                <%--url: '${contextPath}/process/start',--%>
                <%--data: {key: key, tm:new Date().getTime()},--%>
                <%--dataType:'json',--%>
                <%--cache: false,--%>
                <%--success: function(data){--%>
                    <%--if(data.result){--%>
                        <%--layer.msg("启动成功！");--%>

                    <%--}else {--%>
                        <%--layer.msg("启动失败！");--%>
                    <%--}--%>
                    <%--// window.location.href = "findlastVerion";--%>
                <%--}--%>
            <%--});--%>
        <%--});--%>


//        function doUpload() {
//            var file = $("#fileToUpload").val();
//            var xls = new Array();
//            xls = file.split(".");
//            alert(xls[xls.length - 1]);
//            if (xls[xls.length - 1] == "zip"){
////                var formData = new FormData();
////                formData.append("fileHandler",document.getElementById('fileToUpload').files[0]);
////                formData.append("name", $("#name").val());
//                $.ajax({
//                    url: 'repository' ,
//                    type: 'POST',
//                    data: {fileHandler : document.getElementById('fileToUpload').files[0], name : $("#name").val(), tm:new Date().getTime()},
//                    async: false,
//                    cache: false,
//                    dataType: 'json',   //返回值类型
//                    contentType: false,
//                    processData: false,
//                    success : function(data) {
//                        alert(data.message);
//                    },
//                    error : function(result) {
//                        console.info("表单提交错误："+ result);
//                    }
//                });
//            }else {
//                alert("上传暂时只支持.xls后缀的execl表格");
//            }
//        }

        <%--var findlastVerion = function () {--%>
            <%--var param = {};--%>
            <%--$.ajax({--%>
               <%--url: '${contextPath}/process/findlastVerion' ,--%>
               <%--type: 'POST',--%>
               <%--data: param,--%>
               <%--async: false,--%>
               <%--cache: false,--%>
               <%--dataType: 'json',   //返回值类型--%>
               <%--contentType: false,--%>
               <%--processData: false,--%>
               <%--success : function(data) {--%>
                   <%--console.log(data.message);--%>
               <%--},--%>
               <%--error : function(result) {--%>
                   <%--console.info("表单提交错误："+ result);--%>
               <%--}--%>
           <%--});--%>
        <%--}--%>

        $(function () {
            app.findlastVerion();
        })
    </script>
</body>
</html>
